local skels = {}
local kongxian = fk.CreateSkill{
    name = "ym2__kongxian",
    tags = {Skill.Compulsory},
}
Fk:loadTranslationTable{
    ["ym2__kongxian"] = "控弦",
    [":ym2__kongxian"] = "锁定技，你受到过伤害/使用过红色牌/未行动过的回合结束时，你失去此技能，并摸一张牌。",
    ["#ym2__kongxian1"] = "受过伤害的回合结束时",
    ["#ym2__kongxian2"] = "使用过红色牌的回合结束时",
    ["#ym2__kongxian3"] = "未行动过的回合结束时",

    ["$ym2__kongxian1"] = "（射箭声）",
}
kongxian:addEffect(fk.TurnEnd,{
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(kongxian.name) then
            if #player.room.logic:getActualDamageEvents(1, function(e)
                return e.data.to == player
            end) > 0 then
                return true
            end
            if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                local d = e.data
                return d.from == player and d.card.color == Card.Red
            end, Player.HistoryTurn) > 0 then
                return true
            end
            if #player.room.logic:getActualDamageEvents(1, function(e)
                return (e.data.from and e.data.from == player) or e.data.to == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                for _, move in ipairs(e.data) do
                    if move.from == player or move.to == player then
                        return true
                    end
                end
                return false
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
                return e.data.who == player or e.data.recoverBy == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                local d = e.data
                return d.from == player or (d.tos and table.contains(d.tos, player))
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
                return e.data.from == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
                return e.data == player
            end, Player.HistoryTurn)  == 0 and #player.room.logic:getEventsOfScope(GameEvent.Pindian, 999, function(e)
                local dat = e.data
                if dat.from == player or dat.results[player] or table.contains(dat.tos, player) then
                    return true
                end
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
                return e.data.from == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeProperty, 1, function(e)
                local dat = e.data
                return dat.from == player and dat.results and dat.results["kingdomChange"]
            end, Player.HistoryTurn) == 0 then
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        player.room:handleAddLoseSkills(player,"ym2__kongxian")
        player:drawCards(1,kongxian.name)
    end,
})
table.insert(skels,kongxian)

-- 30个备用
for i = 1, 30 do
    local skelA_name = "ym2__kongxian_A"..i
    local skelB_name = "ym2__kongxian_B"..i
    local skelC_name = "ym2__kongxian_C"..i
    local skelA = fk.CreateSkill{
        name = skelA_name,
        tags = {Skill.Compulsory},
    }
    local skelB = fk.CreateSkill{
        name = skelB_name,
        tags = {Skill.Compulsory},
    }
    local skelC = fk.CreateSkill{
        name = skelC_name,
        tags = {Skill.Compulsory},
    }
    Fk:loadTranslationTable{
        [skelA_name] = "控弦",
        [":"..skelA_name] = "锁定技，你受到过伤害的回合结束时，你失去此技能，并摸一张牌。",
        [skelB_name] = "控弦",
        [":"..skelB_name] = "锁定技，你使用过红色牌的回合结束时，你失去此技能，并摸一张牌。",
        [skelC_name] = "控弦",
        [":"..skelC_name] = "锁定技，你未行动过的回合结束时，你失去此技能，并摸一张牌。",
    }
    skelA:addEffect(fk.TurnEnd,{
        anim_type = "drawcard",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(skelA.name) then
                if #player.room.logic:getActualDamageEvents(1, function(e)
                    return e.data.to == player
                  end) > 0 then
                    return true
                end
            end
        end,
        priority = i,
        on_use = function (self, event, target, player, data)
            player:broadcastSkillInvoke(kongxian.name)
            player.room:handleAddLoseSkills(player,"-"..skelA_name)
            player:drawCards(1,skelA.name)
        end,
    })
    skelB:addEffect(fk.TurnEnd,{
        anim_type = "drawcard",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(skelB.name) then
                if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                    local d = e.data
                    return d.from == player and d.card.color == Card.Red
                end, Player.HistoryTurn) > 0 then
                    return true
                end
            end
        end,
        priority = (30 + i),
        on_use = function (self, event, target, player, data)
            player:broadcastSkillInvoke(kongxian.name)
            player.room:handleAddLoseSkills(player,"-"..skelB_name)
            player:drawCards(1,skelB.name)
        end,
    })
    skelC:addEffect(fk.TurnEnd,{
        anim_type = "drawcard",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(skelC.name) then
                if #player.room.logic:getActualDamageEvents(1, function(e)
                    return (e.data.from and e.data.from == player) or e.data.to == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                    for _, move in ipairs(e.data) do
                        if move.from == player or move.to == player then
                            return true
                        end
                    end
                    return false
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
                    return e.data.who == player or e.data.recoverBy == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                    local d = e.data
                    return d.from == player or (d.tos and table.contains(d.tos, player))
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
                    return e.data.from == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
                    return e.data == player
                end, Player.HistoryTurn)  == 0 and #player.room.logic:getEventsOfScope(GameEvent.Pindian, 999, function(e)
                    local dat = e.data
                    if dat.from == player or dat.results[player] or table.contains(dat.tos, player) then
                        return true
                    end
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
                    return e.data.from == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeProperty, 1, function(e)
                    local dat = e.data
                    return dat.from == player and dat.results and dat.results["kingdomChange"]
                end, Player.HistoryTurn) == 0 then
                    return true
                end
            end
        end,
        priority = (60 + i),
        on_use = function (self, event, target, player, data)
            player:broadcastSkillInvoke(kongxian.name)
            player.room:handleAddLoseSkills(player,"-"..skelC_name)
            player:drawCards(1,skelC.name)
        end,
    })
    table.insert(skels,skelA)
    table.insert(skels,skelB)
    table.insert(skels,skelC)
end

return skels